#include "SubsystemBoatBlockBehavior.h"
#include "Subsystems/SubsystemAnimalEntities.h"

#include "GameSingleton.h"
#include "Components/ComponentMiner.h"
#include "Log.h"
#include "Blocks/BoatBlock.h"

namespace PocketSurvival
{
    SubsystemBoatBlockBehavior::SubsystemBoatBlockBehavior()
    {
        m_handleBlocks.push_back(BoatBlock::Index());
    }

    bool SubsystemBoatBlockBehavior::onUse(const Ray3 &ray, ComponentMiner *componentMiner)
    {
        if (Terrain::ExtractContents(componentMiner->getActiveBlockValue()) == BoatBlock::Index())
        {
            RaycastData raycastData = componentMiner->raycast(ray, RaycastMode::Digging);
            if(raycastData.terrainRaycastResult != nullptr)
            {
                m_subsystemAnimalEntities->addAnimalEntity("Boat", raycastData.terrainRaycastResult->hitPoint());
            }
        }
        return false;
    }

    void SubsystemBoatBlockBehavior::load(const nlohmann::json &json)
    {
        m_subsystemAnimalEntities = GameSingleton::singletonPtr->getSingleton<SubsystemAnimalEntities>();
    }

    static const std::string subsystemName = "BoatBlockBehavior";
    const std::string &SubsystemBoatBlockBehavior::getName() const
    {
        return subsystemName;
    }
}
